<?php
/**
 * Custom WP_nav_menu items.
 * @author ATOM STUDIO
 * @url http://www.fennubird.cn
 * @date 2019-12-5
 */
/**
 * Add home to nav menu in main.
 */
add_filter('wp_nav_menu_items', 'wdstar_add_admin_link', 1, 2);
function wdstar_add_admin_link($items, $args){
    if( $args->theme_location == 'main' ){
	    $home_active = is_home()||is_front_page() ? "active": '';
        $item = '<li class="nav-item nav-home"><a title="Home" class="nav-link '. $home_active .'" href="'. esc_url( home_url() ) .'">' . __("首页",'wdstar') . '</a></li>';
        $items = $item . $items;
        $last = '<li class="nav-item ml-md-5 ml-sm-0 search-item d-none d-md-block"><a class="nav-link item-last" href="javascript:;" onclick="return false" title=" '. __("Search",'wdstar').'"><i class="fa fa-search"></i></a></li>';
        $items .= $last;
    }
    return $items;
}

function wd_star_nav_item_class ($classes , $item, $args) {
    if ("main" == $args->theme_location ) {
        $classes[] = "nav-item";
    }
    return $classes;
}
add_filter("nav_menu_css_class","wd_star_nav_item_class",10, 3 );

function wd_star_nav_item_link_class( $atts,$item,$args ) {
    if ( "main" == $args->theme_location ) {
        $atts['class'] = "nav-link";
    }
    return $atts;
}
add_filter("nav_menu_link_attributes","wd_star_nav_item_link_class",10,3);
